package main

import (
	"log"

	"golang.org/x/net/context"
	"google.golang.org/grpc"
	"google.golang.org/grpc/credentials"

	pb "grpc/helloworldgrpc/proto"
)

func main() {
	creds, err := credentials.NewClientTLSFromFile("F:\\study\\gospace\\goweb\\src\\grpc\\helloworldgrpc\\certs\\server.pem", "dev")

	if err != nil {
		log.Println("failed to create tls credentials %v", err)
	}

	conn, err := grpc.Dial(":50052", grpc.WithTransportCredentials(creds))

	defer conn.Close()

	if err != nil {
		log.Println(err)
	}

	c := pb.NewHelloWorldClient(conn)
	ctx := context.Background()
	body := &pb.HelloWorldRequest{
		Referer: "grpc",
	}

	r, err := c.SayHelloWorld(ctx, body)

	if err != nil {
		log.Println(err)
	}

	log.Println(r.Message)
}
